
"""
角色抽取
"""
from models import Chapter
from pydantic import Field
from core.utils import BaseAnalyzer, prompt_dir
from core.alone_analyze.simply_extract import SimplyExtractor
from typing import List


class CharactersAnalyzer(BaseAnalyzer):

    def __init__(self):
        super().__init__(prompt_file=prompt_dir / 'context/c3. 人物塑造分析.md')
        self.simply_extractor = SimplyExtractor()

    def invoke(
            self,
            archived_characters: List = Field(description="人物的历史信息"),
            chapter: Chapter = Field(description="章节信息")
    ):
        prompt = self.template_prompt.format(
            inputs={
                "archived_characters": '\n'.join([str(character) for character in archived_characters]),
                "chapter_content": chapter.chapter_content,
            },
            remove_template_variables=True
        )
        chapter.characterization = self.analyze(prompt)
        return chapter.characterization
